package com.mall.socket;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/socket")
@ResponseBody
public class WebSocketController {

    //推送数据接口
    @PostMapping("/push/{cid}")
    public Map pushToWeb(@PathVariable String cid, String message) {
        Map result = new HashMap();
        for(int i=0;i<10;i++){
            WebSocketServer.sendInfo(message+i,cid);
        }
        result.put("code", 200);
        result.put("msg", "success");
        return result;
    }

    //推送数据接口
    @GetMapping("/selectKey")
    public Map selectKey() {
        Map result = new HashMap();
        result.put("code", 200);
        result.put("msg", WebSocketServer.getWebSocketMap());
        return result;
    }

    //关闭链接
    @PostMapping("/closeKey")
    public String closeKey(String key) {
        WebSocketServer.closeKey(key);
        return "success";
    }
}
